Documentation for Users  2.1.2
Perception Toolbox for Virtual Reality (PTVR) Manual
reticle_on_different_bckgnd_colors.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 """
3 ...\PTVR_Researchers\Python_Scripts\Demos\Pointing\
4  reticle_on_different_bckgnd_colors.py
5 
6 This demo is the same as the reticle.py script except that:
7  - the 'two_colors' parameter is set to "True" in ReticleImageFromDrawing()
8  In this case, the reticle is made of two contours (white and black),
9  which makes it ideal for a background containing dark and bright patches
10  of colors.
11 
12  - there are five Flat Screens with different luminances (from black to
13  white)
14  so that you can move the reticle above dark or bright surfaces and check
15  that the reticle is clearly visible in all cases.
16 
17 Created by Carlos Aguilar in March 2025
18 
19 """
20 
21 from PTVR.Visual import The3DWorld
22 from PTVR.Stimuli.Objects import FlatScreen
23 from PTVR.Stimuli.Scenes import VisualScene
24 from PTVR.Pointing.PointingCursor import *
26 from PTVR.SystemUtils import LaunchThe3DWorld
27 import numpy as np
28 import PTVR.Stimuli.Color as color
29 
30 my_contingency = ImageContingency.HEADSET
31 
32 my_world = The3DWorld()
33 
34 grey_level_1 = 1.0
35 grey_level_2 = 0.75
36 grey_level_3 = 0.5
37 grey_level_4 = 0.25
38 grey_level_5 = 0.0
39 
40 
41 def main():
42 
43  my_scene = VisualScene()
44 
45  reticle_2D_image = RG.ReticleImageFromDrawing(
46  two_colors = True # creates a BICOLOR reticle
47  # note : with a bicolor reticle, the 'reticle_line_width_as_ratio'
48  # parameter refers to the white circle's width.
49  )
50 
51  # If you want to open a window on your PC showing the reticle image
52  # that has just been internally drawn, comment out the following line.
53  # reticle_2D_image.Show()
54 
55  # transform 'reticle_2D_image' into a contingent cursor.
56  my_reticle = ImageToContingentCursor(
57  image=reticle_2D_image,
58  contingency_type=my_contingency)
59  my_scene.place_contingent_cursor(my_reticle)
60 
61  flat_screen_1 = FlatScreen(position_in_current_CS=np.array([-2, 0, 3]),
62  color=color.RGBColor(r=grey_level_1, g=grey_level_1,
63  b=grey_level_1, a=1.0))
64  flat_screen_2 = FlatScreen(position_in_current_CS=np.array([-1, 0, 3]),
65  color=color.RGBColor(r=grey_level_2, g=grey_level_2,
66  b=grey_level_2, a=1.0))
67  flat_screen_3 = FlatScreen(position_in_current_CS=np.array([0, 0, 3]),
68  color=color.RGBColor(r=grey_level_3, g=grey_level_3,
69  b=grey_level_3, a=1.0))
70  flat_screen_4 = FlatScreen(position_in_current_CS=np.array([1, 0, 3]),
71  color=color.RGBColor(r=grey_level_4, g=grey_level_4,
72  b=grey_level_4, a=1.0))
73  flat_screen_5 = FlatScreen(position_in_current_CS=np.array([2, 0, 3]),
74  color=color.RGBColor(r=grey_level_5, g=grey_level_5,
75  b=grey_level_5, a=1.0))
76  my_scene.place(flat_screen_1, my_world)
77  my_scene.place(flat_screen_2, my_world)
78  my_scene.place(flat_screen_3, my_world)
79  my_scene.place(flat_screen_4, my_world)
80  my_scene.place(flat_screen_5, my_world)
81 
82  my_world.add_scene(my_scene)
83  my_world.write()
84 
85 
86 if __name__ == "__main__":
87  main()
88  LaunchThe3DWorld() # Launch the Experiment with PTVR.
def LaunchThe3DWorld(jsonFileCategory="Externals")
Definition: SystemUtils.py:182